package com.lst.api.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lst.api.constant.BuyTypeEnum;
import com.lst.api.constant.InsurancePayWayEnum;
import com.lst.api.entity.AssetsCarInfo;
import com.lst.api.exception.RequestParamErrorException;
import com.lst.tools.basics.utils.DateUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 资产信息中的车辆信息
 *
 * @author Frank
 * @date 2019-12-30 10:31:37
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class AssetsCarInfoVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "carBrandId", value = "车品牌id", required = true, dataType = "Long")
    private Long carBrandId;

    @ApiModelProperty(name = "carBuyAt", value = "购买车日期", required = true, dataType = "Date")
    @JsonFormat(pattern = DateUtils.DATE_FORMAT_1)
    private Date carBuyAt;

    @ApiModelProperty(name = "carBuyTotalAmount", value = "购车总金额", required = true, dataType = "Double")
    private Double carBuyTotalAmount;

    @ApiModelProperty(name = "carBuyType", value = "购车方式    0:一次性    1:按揭", required = true, dataType = "String")
    private String carBuyType;

    @ApiModelProperty(name = "insuranceCompany", value = "保险公司", required = true, dataType = "String")
    private String insuranceCompany;

    @ApiModelProperty(name = "insurancePayWay", value = "保险缴费方式    0:月缴    1:年缴", required = true, dataType = "String")
    private String insurancePayWay;

    @ApiModelProperty(name = "insurancePayAmount", value = "保险缴纳金额", required = true, dataType = "Double")
    private Double insurancePayAmount;

    public AssetsCarInfoVo(AssetsCarInfo assetsCarInfo) {
        if (assetsCarInfo == null) {
            return;
        }
        this.carBrandId = assetsCarInfo.getCarBrandId();
        this.carBuyAt = assetsCarInfo.getCarBuyAt();
        this.carBuyTotalAmount = assetsCarInfo.getCarBuyTotalAmount();
        this.carBuyType = assetsCarInfo.getCarBuyType();
        this.insuranceCompany = assetsCarInfo.getInsuranceCompany();
        this.insurancePayWay = assetsCarInfo.getInsurancePayWay();
        this.insurancePayAmount = assetsCarInfo.getInsurancePayAmount();
    }

    public void check() {
        boolean check = this.carBrandId != null
                && this.carBuyAt != null
                && this.carBuyTotalAmount != null
                && BuyTypeEnum.getByKey(this.carBuyType) != null
                && StringUtils.isNotBlank(this.insuranceCompany)
                && InsurancePayWayEnum.getByKey(this.insurancePayWay) != null
                && this.insurancePayAmount != null;
        if (!check) {
            throw new RequestParamErrorException("AssetsCarInfoVo请求参数不合法！");
        }
    }
}